home *** CD-ROM | disk | FTP | other *** search
- ' Program EX_0701.BAS
- ' Listing 14B - see documentation in TUTOR.SSS
-
- const ARRIVL = 1, STARTA = 2, ENDACT = 3, NEXTAC = 4
- const ORD1 = 1, ORD2 = 2, DELUX1 = 3, DELUX2 = 4
-
- dim shared server(1 to 2)
-
- declare sub prime ()
- declare sub preemp ()
- declare function sindex ()
- declare function shortr ()
-
- rem $include: 'SSSB.H'
-
- call prime
-
- do
- ecode = NEXTEV
- if ecode > 0 then
- select case ecode
-
- case ARRIVL
- CREATE EX(2), 0
- SETA 1, 0
- SETA 2, TR(1, 2, 3)
- if RA < .25 then
- SETIDE DELUX1
- else
- SETIDE ORD1
- end if
- SCHED 0, NEXTAC, IDE
-
- case NEXTAC
- if server(1) > 0 then
- SCHED 0, STARTA, IDE
- elseif server(2) > 0 then
- SCHED 0, STARTA, IDE + 1
- elseif IDE = DELUX1 then
- preemp
- else
- QUEUE shortr, 0
- end if
-
- case STARTA
- s = sindex
- server(s) = server(s) - 1
- SCHED A(2), ENDACT, IDE
-
- case ENDACT
- s = sindex
- server(s) = server(s) + 1
- if IDE < DELUX1 then TALLY 1, A(1)
- DISPOS
- if NQ(s + 2) > 0 then
- REMVFQ s + 2, 1
- SCHED 0, STARTA, IDE
- elseif NQ(s) > 0 then
- REMVFQ s, 1
- SCHED 0, STARTA, IDE
- end if
-
- end select
- end if
- loop while ecode > 0
-
- title$ = " "
- SUMRY sadd(title$)
-
- sub preemp
- QUEUE 5, 0
- i = 1
- if NC > 0 then
- for j = 1 to NC
- if IDIC(i) > ORD2 or NEIC(i) <> ENDACT then
- i = i + 1
- end if
- next j
- end if
-
- if i <= NC then
- remt = TIC(i) - t
- REMVFC i
- preide = ide
- SETA 1, A(1) + 1
- SETA 2, remt
-
- title$ = "LIFO "
- SETQDC 1, sadd(title$)
- QUEUE IDE, 0
- title$ = "FIFO "
- SETQDC 1, sadd(title$)
- REMVFQ 5, 1
- SCHED 0, STARTA, preide + 2
- else
- REMVFQ 5, 1
- QUEUE shortr, 0
- end if
- end sub
-
- sub prime
- server(1) = 1
- server(2) = 1
- INIQUE 5, 3, 1
- title$ = "Interrupts "
- INISTA 1, sadd(title$), 0, 0, 0, 0
- SIMEND 60
- CREATE 0, 0
- end sub
-
- function shortr
- if NQ(4) + NQ(2) < NQ(3) + NQ(1) then SETIDE IDE + 1
- shortr = IDE
- end function
-
- function sindex
- if IDE < DELUX1 then
- sindex = IDE
- else
- sindex = IDE - ORD2
- end if
- end function
-